<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.model.User"%>
<%@ page import="com.control.UserControl"%>
<%@ page import="com.util.PageResultSet"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>查询信息</title>
	</head>
	<body>
		<%
	    request.setCharacterEncoding("UTF-8");
	    int curPage = 1;
	    String ToolBar = "";
	    int user_role = 4;
	    if(request.getParameter("role")!=null){
	    	user_role = Integer.parseInt(request.getParameter("role"));
	    	session.setAttribute("user_role", user_role);
	    }
	    
		%>
		<table width="98%" border="0" align="center">
			<tr>
				<td></td>
			</tr>
			<tr>
				<td></td>
			</tr>
			<tr>
				<td>
					<fieldset>
						<legend> 
							信息列表 
						</legend>
						<form action="Info_show.jsp" name="form1" method="post">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr height="10">
									<td></td>
								</tr>
								<tr align="center">
									<td align="center">
										<span style="color: rgb(55, 107, 165); margin-top: 10px;">类&nbsp;&nbsp;别：</span> 
									   	<select name="role" style="margin-top: 10px;">
									   	<option value="2" <%if(user_role==2) {%> selected="selected" <%} %>>教务处</option>
									   	<option value="3" <%if(user_role==3) {%> selected="selected" <%} %>>教师</option>
									   	<option value="4" <%if(user_role==4) {%> selected="selected" <%} %>>学生</option>
									   	</select>	 
									   	<input type="submit" value="查询" /> 
								       
										<input name="insert" type="button" value="添加用户"
											onclick="window.location.href='user_insert.jsp'" />
									</td>
								</tr>
							</table>
							<table width="90%" border="0" align="center" cellspacing="0"
								cellpadding="0">
								<tr>
									<td height="20"></td>
								</tr>
								<tr>
									<td>
										<table border="1" width="99%" align="center" cellpadding="0"
											cellspacing="1" class="resultTable">
											<tr>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													学号
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													姓名
												</td>
												<td width="2%" height="25" align="center" bgcolor="#D9F0FF">
													性别
												</td>
												<td width="5%" height="25" align="center" bgcolor="#D9F0FF">
													操作
												</td>
								</tr>
								<%
									UserControl uc = new UserControl();
									ArrayList<User> list = new ArrayList<User>();
									list = uc.getAllUser(user_role);
									if(request.getParameter("cur_page")!= null) {
										curPage = Integer.parseInt(request.getParameter("cur_page")); 
									}
									PageResultSet p = new PageResultSet(list,curPage);
									ArrayList<User> nowlist = new ArrayList<User>();
									nowlist = (ArrayList<User>)p.getData();
									System.out.print(list.size());
									for(int i=0; i<nowlist.size(); i++) {
										User user = nowlist.get(i);
							 	%>
								 	<tr>
        								<td height="25" align="center"><%=user.getUsername()%></td>
 										<td height="25" align="center"><%=user.getName()%></td>
 										<td height="25" align="center"><%=user.getSex()%></td>
 		 								<td height="25" align="center"><a href="javascript:if(confirm('确认删除吗?'))window.location='student_delete.jsp?id=<%=user.getId()%>'">删除</a></td>
   									</tr>
   									<%}
   										
										String fileName = "Info_show.jsp";
										ToolBar = p.getToolBar(fileName);
									%>
							</table>
							<%=ToolBar %>
							</td>
							</tr>
							</table>
						</form>
					</fieldset>
				</td>
			</tr>
		</table>
	</body>
</html>
